var express = require('express');
var router = express.Router();
var v_user=require('../models/validate/user');
var v=require('../models/validate/category');
var model= require('../models/db/model');

//获取文章提交页面
router.get('/add',v_user.checkLogin,function(req, res, next) {
  res.render('category/add',{title:'分类添加'});
});
//获取文章提交的内容
router.post('/add',v_user.checkLogin,v.add,function(req, res, next) {

  var data=req.body;
    Model('category').create(data,function(err,doc){
        if(err){
            req.flash('error',err);
            return res.redirect('back');
        }else{
            req.flash('success','分类添加成功');
            res.redirect('/articles/add');
        }
    })
});

module.exports = router;
